using UnityEngine;
using System.Collections;

public class EnemyBehaviour : MonoBehaviour
{
    public float vision = 15;
    private int health = 3;
    private GameObject player;
    private Patrol patrolScript;
    private Attack attackScript;

    public bool IsAlive
    {
        get { return health > 0; }
    }

	void Start () {
        patrolScript = gameObject.GetComponent<Patrol>();
        attackScript = gameObject.GetComponent<Attack>();
        player = GameObject.FindGameObjectWithTag("Player");
	}
	
	void Update () {
        if (IsAlive)
        {
            float distance = Vector3.Distance(player.transform.position, transform.position);

            if (distance < vision)
            {
                attackScript.enabled = true;
                patrolScript.enabled = false;
            }
            else
            {
                attackScript.enabled = false;
                patrolScript.enabled = true;
            }
        }
        else
        {
            Destroy(gameObject);
        }
	}

    public void DecreaseHealth()
    {
        health--;
    }
}
